﻿function move(to_left, to_top, div_id) {
    var msgObj = document.getElementById(div_id);
    var left = parseInt(msgObj.style.left);
    var top = parseInt(msgObj.style.top);
    left += to_left;
    top += to_top;
    msgObj.style.left = left + "px";
    msgObj.style.top = top + "px";
    msgObj.style.position = "absolute";
};

function show_dialog(div_id) {
    var msgObj = document.getElementById(div_id);
    msgObj.style.display = "block";
    msgObj.style.left = "250px";
    msgObj.style.top = "160px";
    var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
    var isMove = false, isDown = false;
    msgObj.onmousedown = function () {
        x0 = event.clientX;
        y0 = event.clientY;
        var top = parseInt(msgObj.style.top);
        if ((y0 - top) <= 30) {
            isMove = false;
            isDown = true;
        } else isDown = false;
    }
    msgObj.onmousemove = function () {
        if (isDown) {
            isMove = true;
            var x = event.clientX;
            var y = event.clientY;
            var to_left = x - x0;
            var to_top = y - y0;
            move(to_left, to_top, div_id);
            x0 += to_left;
            y0 += to_top;
        }
    }
    msgObj.onmouseup = function () {
        x1 = event.clientX;
        y1 = event.clientY;
        if (isMove == true) {
            var to_left = x1 - x0;
            var to_top = y1 - y0;
            if ((to_left > 5 || to_left < -5) || (to_top > 5 || to_top < -5)) {
                move(to_left, to_top, div_id);
            }
            isMove = false;
            isDown = false;
        }
    }
};

function show_meeting() {
    show_dialog("msgDiv");
}
function show_device() {
    show_dialog("deviceDiv");
}
